<div carousel-item="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form" lay-filter="fromSite">
            <div class="layui-form-item">
                <input type="text" hidden name="serviceId"/>
                <div class="layui-inline">
                    <label class="layui-form-label required">站点名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="siteName" lay-verify="required" lay-reqtext="站点名称不能为空"
                               placeholder="请输入站点名称"
                               value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label required">站点域名</label>
                    <div class="layui-input-block">
                        <input type="text" name="siteDomain" lay-verify="required" lay-reqtext="站点域名称不能为空"
                               placeholder="请输入站点域名"
                               value="" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label required">端口号</label>
                    <div class="layui-input-block">
                        <input type="text" name="sitePort" lay-verify="required" lay-reqtext="站点端口号不能为空"
                               placeholder="请输入站点端口号"
                               value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label required">站点类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="siteType" value="0" title="静态网站" checked="">
                        <input type="radio" name="siteType" value="1" title="后台JAVA">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label required">是否宝塔</label>
                    <div class="layui-input-block">
                        <input type="radio" name="isBt" value="0" title="不是" checked="">
                        <input type="radio" name="isBt" value="1" title="是">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">单行选择框</label>
                    <div class="layui-input-block">
                        <select name="phpVersion" id="phpVersion" lay-filter="phpVersionFilter">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">shell脚本</label>
                <div class="layui-input-block">
                <textarea name="siteShell" placeholder="请输入内容" lay-reqtext="shell脚本不能为空" lay-verify="required"
                          class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">站点描述</label>
                <div class="layui-input-block">
                <textarea name="siteDescribe" placeholder="请输入内容" lay-reqtext="站点描述不能为空" lay-verify="required"
                          class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="siteSaveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'common', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            common = layui.common
            , laydate = layui.laydate;
        $ = layui.$;


        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        var serverId = parent.serverId;
        form.val("fromSite", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
             "serviceId": serverId
        });
        common.ajaxGet('/api/bt/php/version?serverId=' + serverId, function (_data) {
                if (_data.resCode === '0000') {
                    for (var i = 0; i < _data.resultList.length; i++) {
                        $("#phpVersion").append("<option value=\"" + _data.resultList[i].version + "\">" + _data.resultList[i].name + "</option>");
                    }
                    //重新渲染
                    layui.form.render("select");
                }
            }
        )

        //监听提交
        form.on('submit(siteSaveBtn)', function (data) {
            console.log(data)
            if(data.field.isBt === '0'){
                common.ajaxPost('/api/server/site/add',
                    JSON.stringify(data.field)
                    , function (_data) {
                        if (_data.resCode === '0000') {
                            layer.close(parentIndex);
                            layer.msg(_data.resDesc, {icon: 6});
                            table.reload('currentTableId');
                        } else {
                            layer.msg(_data.resDesc, {icon: 7});
                        }
                    }
                )
            }
            if(data.field.isBt === '1'){
                common.ajaxPost('/api/bt/site/add',
                    JSON.stringify(data.field)
                    , function (_data) {
                        if (_data.resCode === '0000') {
                            layer.close(parentIndex);
                            layer.msg(_data.resDesc, {icon: 6});
                            table.reload('subCurrentTableId');
                        } else {
                            layer.msg(_data.resDesc, {icon: 7});
                        }
                    }
                )
            }
            return false;
        });
    });
</script>

